(function() {

this.pasta = this.pasta || {};
this.pasta.webgui = this.pasta.webgui || {};

this.pasta.webgui.RadioButton = pasta.webgui.Control.extend(
{
	init : function() 
	{
		this._super();
		
		this.canvas.style.background = "url(img/control/radioButton/radioButton.png)";
		this.canvas.style.backgroundPosition = "left top";
		
		this.setButtonMode(true);
		this.canvas.style.cursor = "pointer";
		
		this.setWidth(16);
		this.setHeight(16);
		
		this.selected = false;
		this._onChange = null;
	},
	
	syncSibling : function()
	{
		var owner = this.getParent();
		
		if (owner instanceof pasta.webgui.ContainerControl)
		{
			var item = null;
			
			for (var i = 0; i < owner.controls.getLength(); i++)
			{
				item = owner.controls.get(i);
				
				if (item instanceof pasta.webgui.RadioButton)
				{
					if (item != this)
						item.setSelected(false);
				}
			}
		}
	},
	
	//------------------ Event Handler -----------------
	
	doMouseDown : function()
	{
		this.selected = true;
		this.canvas.style.backgroundPosition = "left bottom";
		
		this.syncSibling();
		
		if (this._onChange != null)
			this._onChange.callHandler(this);
		
		this._super();
	},
	
	//------------------ Setter & Getter -----------------
	
	isSelected : function()
	{
		return this.selected;
	},
	
	setSelected : function(data)
	{
		this.selected = data;
		this.canvas.style.backgroundPosition = this.selected ? "left bottom" : "left top";
		
		if (this.selected)
			this.syncSibling();
	},
	
	//------------------ Event -----------------
	
	getOnChange : function()
	{
		if (this._onChange == null)
			this._onChange = new pasta.util.EventObj();
		
		return this._onChange;
	},
});

})();